package com.zhhl.util;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintStream;

public class UtilTools
{
  public static void writeFile(String filePathAndName, String fileContent)
  {
    try
    {
      File f = new File(filePathAndName);
      if (!f.getParentFile().exists()) {
        f.getParentFile().mkdirs();
      } else {
        File[] files = f.getParentFile().listFiles();
        for (int i = 0; i < files.length; i++) {
          if (files[i].getName().indexOf("category-") <= -1)
          {
            files[i].delete();
          }
        }
      }
      if (!f.exists()) {
        f.createNewFile();
      }
      OutputStreamWriter write = new OutputStreamWriter(new FileOutputStream(f), "GB2312");
      BufferedWriter writer = new BufferedWriter(write);
      writer.write(fileContent);
      writer.close();
    } catch (Exception e) {
      System.out.println("写文件内容操作出错");
      e.printStackTrace();
    }
  }
}